package com.douqu.game.battle.controller;

import com.douqu.game.battle.controller.sprite.PlayerController;
import com.douqu.game.battle.controller.sprite.SpriteController;
import com.douqu.game.battle.entity.tmp.PlayerBattleTmp;
import com.douqu.game.battle.entity.tmp.SpriteBattleTmp;
import com.douqu.game.battle.util.BattleUtils;
import com.douqu.game.core.astar.AStar;
import com.douqu.game.core.astar.AstarMap;
import com.douqu.game.core.config.challenge.MapConfig;
import com.douqu.game.core.e.E_BattleDetailType;
import com.douqu.game.core.entity.activity.MatchBaseInfo;
import com.douqu.game.core.entity.battle.BattleInitParam;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.util.CoreUtils;

/**
 * Created by bean on 2017/7/25.
 */
public class PVPController extends BattleController {

    public PVPController(String battleId, PlayerController player, SpriteController target, SGCommonProto.E_BATTLE_TYPE battleType, E_BattleDetailType battleDetailType, String targetData, String targetName, BattleInitParam initParam)
    {
        super(battleId, player, target, battleType, battleDetailType, targetData, targetName, initParam);

        this.targetData = targetData;

        MapConfig mapConfig = DataFactory.getInstance().getGameObject(DataFactory.MAP_KEY, initParam.getMapId());
        LogUtils.debug("mapConfig -> " + mapConfig);
        this.astar = new AStar(new AstarMap(AstarMap.AnchorPos.BottomLeft, mapConfig.mapType==1? BattleUtils.BATTLE_MAP_1:BattleUtils.BATTLE_MAP_2));
    }

    @Override
    public void init()
    {
        super.init();

        SpriteBattleTmp pbt2 = new PlayerBattleTmp();
        pbt2.init(this, target, ConstantFactory.BATTLE_TEAM_2);
        target.setAttachment(pbt2);

        if(!target.isOnlinePlayer())
        {
            pbt2.setReady(true);
        }

        pbt2.setTargetBattleTmp(source.getAttachment());
        source.getAttachment().setTargetBattleTmp(pbt2);

        battleDetail.getTeam2Info().setMaster(pbt2.getMasterSoldier().getSpriteTemp());

        PlayerController targetController = (PlayerController) target;
        MatchBaseInfo baseInfo = new MatchBaseInfo(targetController.getPlayer(), target.getServerId());
        if(!CoreUtils.isNullOrEmpty(targetName))
            baseInfo.setName(targetName);
        battleDetail.getTeam2Info().setBaseInfo(baseInfo);

        if(E_BattleDetailType.PVP_AI_MAJOR == battleDetailType || E_BattleDetailType.PVP_AI_OFFICIAL_RANK == battleDetailType)
        {
            battleDetail.getTeam2Info().setIndexInfo(targetData);
        }

        if(!battleDetailType.isPlayerBattle())
        {
            readyStart();
        }
    }







}
